﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
#foreach($u in $TableInfos)
#beforeall 
#each 
namespace CMN.Models
{
    /// <summary>
    /// ${u.TabCaption}Service
    /// </summary>
    public class ${u.TabName}Service: IDataService<${u.TabName}Entity>
    {
        /// <summary>
        /// 新增${u.TabCaption}
        /// </summary>
        /// <param name="${u.TabName}Entity"></param>
        /// <returns>string</returns>
        public string Insert(${u.TabName}Entity ${u.TabName.ToLower()}Entity)
        {
            ${u.TabName.ToLower()}Entity.DataTable_Action = DataTableAction.Insert;
            ${u.TabName} bll= new ${u.TabName}();
            if (bll.InsertUpdateDelete(${u.TabName.ToLower()}Entity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 返回${u.TabCaption}查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<${u.TabName}Entity> List(QueryParam qp,out int count)
        {
            ${u.TabName} bll= new ${u.TabName}();
            return bll.List(qp, out count);
        }

        /// <summary>
        /// 更新${u.TabCaption}
        /// </summary>
        /// <param name="${u.TabName}"></param>
        /// <returns>string</returns>
        public string Update(${u.TabName}Entity ${u.TabName.ToLower()}Entity)
        {
            ${u.TabName.ToLower()}Entity.DataTable_Action = DataTableAction.Update;
            ${u.TabName} bll= new ${u.TabName}();
            if (bll.InsertUpdateDelete(${u.TabName.ToLower()}Entity) > 0)
            {
                  return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除${u.TabCaption}
        /// </summary>
        /// <param name="${u.TabName}"></param>
        /// <returns>string</returns>
        public string Delete(${u.TabName}Entity ${u.TabName.ToLower()}Entity)
        {
            ${u.TabName.ToLower()}Entity.DataTable_Action = DataTableAction.Delete;
            ${u.TabName} bll= new ${u.TabName}();
            if (bll.InsertUpdateDelete(${u.TabName.ToLower()}Entity) > 0)
            {
                  return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删${u.TabCaption}
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>string</returns>
        public string DeleteList(string idList)
        {
            string[] list =Utils.SplitString(idList,"_");
            string strDel=Utils.ArrayToString(list,",",false);
            ${u.TabName} bll= new ${u.TabName}();
            if (bll.DelList(strDel) > 0)
            {
                 return "";
            }
            else
            {
                return "失败";
            }

        }

        /// <summary>
        /// 返回单个${u.TabCaption}
        /// </summary>
        /// <param name="id"></param>
        /// <returns>${u.TabName}Entity</returns>
        public ${u.TabName}Entity Look(int id)
        {
            ${u.TabName} bll= new ${u.TabName}();
            return bll.Disp(id);
        }
    }
}
#end